/**
 * @FileName: ServerApiImpl.java
 * @Package:com.bdtop.dbl.server.impl
 * @Description: TODO
 * @author: MingjunLi
 * @date:2014-9-16
 * @version V1.0
 */

package com.bdtop.dbl.server.impl;

import com.bdtop.dbl.model.Fence;
import com.bdtop.dbl.server.ServerApi;
import com.bdtop.dbl.server.request.AddressRequest;
import com.bdtop.dbl.server.request.AllDeviceInfoRequest;
import com.bdtop.dbl.server.request.DeviceAddRequest;
import com.bdtop.dbl.server.request.DeviceDelRequest;
import com.bdtop.dbl.server.request.DeviceInfoRequest;
import com.bdtop.dbl.server.request.DeviceModiRequest;
import com.bdtop.dbl.server.request.FenceAddRequest;
import com.bdtop.dbl.server.request.FenceDelRequest;
import com.bdtop.dbl.server.request.FenceModiRequest;
import com.bdtop.dbl.server.request.FenceSetRequest;
import com.bdtop.dbl.server.request.GetAllPositionRequest;
import com.bdtop.dbl.server.request.GetAuthCodeRequest;
import com.bdtop.dbl.server.request.GetDeviceListRequest;
import com.bdtop.dbl.server.request.GetFenceListRequest;
import com.bdtop.dbl.server.request.GetImgRequest;
import com.bdtop.dbl.server.request.GetLogListRequest;
import com.bdtop.dbl.server.request.GetMsgsRequest;
import com.bdtop.dbl.server.request.GetVersionRequest;
import com.bdtop.dbl.server.request.HistoryTrackRequest;
import com.bdtop.dbl.server.request.LoginOutRequest;
import com.bdtop.dbl.server.request.LoginRequest;
import com.bdtop.dbl.server.request.ModImgRequest;
import com.bdtop.dbl.server.request.PositionRequest;
import com.bdtop.dbl.server.request.RegisterRequest;
import com.bdtop.dbl.server.request.ResetPasswordRequest;
import com.bdtop.dbl.server.request.SendSmsRequest;
import com.bdtop.dbl.server.request.UpdateCidRequest;
import com.bdtop.dbl.server.request.UpdatePasswordRequest;
import com.bdtop.dbl.server.request.VerifyPhoneNumberRequest;
import com.bdtop.dbl.server.request.VerifyPhoneNumberRequest.VerifyParams;
import com.bdtop.dbl.thirdparty.asynchttp.RequestCallback;

/**
 * @ClassName: ServerApiImpl
 * @Description: TODO
 * @author: MingjunLi
 * @date:2014-9-16
 */
public class HttpServerApiImpl implements ServerApi {

    @Override
    public void register(String phoneNumber, RequestCallback callback) {
        RegisterRequest request = new RegisterRequest(callback);
        request.setParams(phoneNumber);
        request.execute();
    }

    @Override
    public void verify(VerifyParams params, RequestCallback callback) {
        VerifyPhoneNumberRequest request = new VerifyPhoneNumberRequest(callback);
        request.setParams(params);
        request.execute();
    }

    @Override
    public void login(String phoneNumber, String password, RequestCallback callback) {
        LoginRequest request = new LoginRequest(callback);
        request.setParams(phoneNumber, password);
        request.execute();
    }

    @Override
    public void getDeviceList(String loginSign, RequestCallback callback) {
        GetDeviceListRequest request = new GetDeviceListRequest(callback);
        request.setParams(loginSign);
        request.execute();
    }

    @Override
    public void getPosition(String sign, String mdn, RequestCallback callback) {
        PositionRequest request = new PositionRequest(callback);
        request.setParams(sign, mdn);
        request.execute();
    }

    @Override
    public void getHistoryTrack(String sign, String mdn, long utc1, long utc2,
            RequestCallback callback) {
        HistoryTrackRequest request = new HistoryTrackRequest(callback);
        request.setParams(sign, mdn, String.valueOf(utc1), String.valueOf(utc2));
        request.execute();
    }

    @Override
    public void fenceAdd(String sign, String mdn, String fencename, double lon, double lat,
            int radius, RequestCallback callback) {
        FenceAddRequest request = new FenceAddRequest(callback);
        request.setParams(sign, mdn, fencename, String.valueOf(lon), String.valueOf(lat),
                String.valueOf(radius));
        request.execute();
    }

    @Override
    public void deviceAdd(String sign, String IMEI, RequestCallback callback) {
        DeviceAddRequest request = new DeviceAddRequest(callback);
        request.setParams(sign, IMEI);
        request.execute();
    }

    @Override
    public void getMsgs(String sign, RequestCallback callback) {
        GetMsgsRequest request = new GetMsgsRequest(callback);
        request.setParams(sign);
        request.execute();
    }

    @Override
    public void getFences(String sign, String mdn, RequestCallback callback) {
        GetFenceListRequest request = new GetFenceListRequest(callback);
        request.setParams(sign, mdn);
        request.execute();
    }

    @Override
    public void fenceDel(String sign, String fence_id, RequestCallback callback) {
        FenceDelRequest request = new FenceDelRequest(callback);
        request.setParams(sign, fence_id);
        request.execute();
    }

    @Override
    public void fenceSet(String sign, String mdn, String fence_id, String open,
            RequestCallback callback) {
        FenceSetRequest request = new FenceSetRequest(callback);
        request.setParams(sign, fence_id, mdn, open);
        request.execute();
    }

    @Override
    public void fenceModi(String sign, String mdn, Fence fence, RequestCallback callback) {
        FenceModiRequest request = new FenceModiRequest(callback);
        request.setParams(sign, mdn, fence);
        request.execute();
    }

    @Override
    public void deviceDel(String sign, String mdn, RequestCallback callback) {
        DeviceDelRequest request = new DeviceDelRequest(callback);
        request.setParams(sign, mdn);
        request.execute();
    }

    @Override
    public void sendSms(String sign, String mdn, String smscmd, RequestCallback callback) {
        SendSmsRequest request = new SendSmsRequest(callback);
        request.setParams(sign, mdn, smscmd);
        request.execute();
    }

    @Override
    public void getAllPosition(String sign, RequestCallback callback) {
        GetAllPositionRequest request = new GetAllPositionRequest(callback);
        request.setParams(sign);
        request.execute();
    }

    @Override
    public void deviceModi(String sign, String mdn, String name, Boolean power,
            Integer locationMode, String[] phones, RequestCallback callback) {
        DeviceModiRequest request = new DeviceModiRequest(callback);
        request.setParams(sign, mdn, name, power, locationMode, phones);
        request.execute();
    }

    @Override
    public void deviceInfo(String sign, String mdn, RequestCallback callback) {
        DeviceInfoRequest request = new DeviceInfoRequest(callback);
        request.setParams(sign, mdn);
        request.execute();
    }

    @Override
    public void getVersion(RequestCallback callback) {
        GetVersionRequest request = new GetVersionRequest(callback);
        request.execute();
    }

    @Override
    public void getAuthCode(String user_number, RequestCallback callback) {
        GetAuthCodeRequest request = new GetAuthCodeRequest(callback);
        request.setParams(user_number);
        request.execute();
    }

    @Override
    public void resetPassword(String user_number, String password, String verify_code,
            RequestCallback callback) {
        ResetPasswordRequest request = new ResetPasswordRequest(callback);
        request.setParams(user_number, password, verify_code);
        request.execute();
    }

    public void upodatePassword(String sign, String password,String srcpw, RequestCallback callback) {
        UpdatePasswordRequest request = new UpdatePasswordRequest(callback);
        request.setParams(sign, password,srcpw);
        request.execute();
    }

    @Override
    public void getLogList(String sign, String startTime, String endTime, RequestCallback callback) {
        GetLogListRequest request = new GetLogListRequest(callback);
        request.setParams(sign, startTime, endTime);
        request.execute();
    }

    @Override
    public void updateImgRequest(String sign, String imgid,  String imgData,
            RequestCallback callback) {
        ModImgRequest request = new ModImgRequest(callback);
        request.setParams(sign, imgid, imgData);
        request.execute();
    }

    @Override
    public void getImg(String sign, String imgid,  RequestCallback callback) {
        GetImgRequest request = new GetImgRequest(callback);
        request.setParams(sign, imgid);
        request.execute();
    }

    @Override
    public void loginOut(String sign, RequestCallback callback) {
        LoginOutRequest request = new LoginOutRequest(callback);
        request.setParams(sign);
        request.execute();
    }

    @Override
    public void updateCid(String sign, String cid, RequestCallback callback) {
        UpdateCidRequest request = new UpdateCidRequest(callback);
        request.setParams(sign, cid);
        request.execute();
    }

    @Override
    public void getAllDeviceInfo(String sign, RequestCallback callback) {
        AllDeviceInfoRequest request = new AllDeviceInfoRequest(callback);
        request.setParams(sign);
        request.execute();
    }

	@Override
	public void getAddressInfo(String sign, double lon, double lat , RequestCallback callback) {
		AddressRequest request = new AddressRequest(callback);
		request.setParams(sign, lon, lat);
		request.execute();
	}

}
